package com.citywithincity.db.meta;

import org.codehaus.jackson.annotate.JsonIgnore;

import com.damai.meta.MetaData;

/**
 * 数据库字段结构
 * @author renxueliang
 *
 */
public class ColumnStruct extends MetaData {
	/**
	 * 下标，用来排序
	 */
	private int index;
	
	/**
	 * 是否可空
	 */
	private boolean nullable;
	/**
	 * key类型
	 */
	private int keyType;
	/**
	 * 是否自增加
	 */
	private boolean auto;
	/**
	 * 最大长度
	 */
	private long maxLen;
	/**
	 * 对应的数据库class
	 */
	@JsonIgnore
	private Class<?> clazz;
	
	/**
	 * 数据库原始类型
	 */
	
	private String rawType;
	
	/**
	 * 数据库中的类型
	 */
	private int type;
	
	/**
	 * 默认值
	 */
	private String defaultValue;
	
	private String table;
	
	
	private String select;
	
	public ColumnStruct(String table){
		this.table = table;
	}
	
	public String getTable(){
		return table;
	}
	

	
	public Class<?> getClazz() {
		return clazz;
	}


	public void setClazz(Class<?> clazz) {
		this.clazz = clazz;
	}


	public boolean isNullable() {
		return nullable;
	}


	public void setNullable(boolean nullable) {
		this.nullable = nullable;
	}


	public int getKeyType() {
		return keyType;
	}


	public void setKeyType(int keyType) {
		this.keyType = keyType;
	}


	public boolean isAuto() {
		return auto;
	}


	public void setAuto(boolean auto) {
		this.auto = auto;
	}


	public long getMaxLen() {
		return maxLen;
	}


	public void setMaxLen(long maxLen) {
		this.maxLen = maxLen;
	}

	@JsonIgnore
	public boolean isPk() {
		return keyType==KeyType.Primary;
	}
	
	public String getRawType() {
		return rawType;
	}
	public void setRawType(String rawType) {
		this.rawType = rawType;
	}
	public int getType() {
		return type;
	}
	public void setType(int type) {
		this.type = type;
	}
	public String getDefaultValue() {
		return defaultValue;
	}
	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}
	
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return new StringBuilder("{name:").append(name).append(',').append("type:").append(rawType).append('}').toString();
	}

	public String getSelect() {
		return select;
	}

	public void setSelect(String select) {
		this.select = select;
	}

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}
	

}
